package com.helasasa.maxfunds.lineofcredit.cashloan.ghana.screen.proof.subview

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.helasasa.maxfunds.lineofcredit.cashloan.R
import org.json.JSONObject

interface IProofGhanaDateListener {
    fun onClick(tid: String)
}

class ProofGhanaDate : LinearLayout {

    private lateinit var title: TextView
    private lateinit var input: EditText
    private lateinit var inputContainer: RelativeLayout
    private lateinit var click: View

    private var bindData: JSONObject? = null
    private var onItemClick: IProofGhanaDateListener? = null

    constructor(context: Context) : super(context) {
        initializeView(context)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initializeView(context)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initializeView(context)
    }

    @SuppressLint("NotifyDataSetChanged")
    private fun initializeView(context: Context) {
        inflate(context, R.layout.view_ghana_proof_date, this)
        orientation = VERTICAL

        title = findViewById(R.id.title)
        input = findViewById(R.id.proofDateInput)
        inputContainer = findViewById(R.id.inputContainer)
        click = findViewById(R.id.proofDateClick)

        click.setOnClickListener {
            onItemClick?.onClick(bindData?.optString("paramName") ?: "")
        }
    }

    fun setBindData(jsonObject: JSONObject?, onClick: IProofGhanaDateListener?) {
        this.onItemClick = onClick
        this.bindData = jsonObject
        setTitle(jsonObject?.optString("title"))
        setInputHint(jsonObject?.optString("hint"))
        setInputText(jsonObject?.optString("content"))
    }

    fun setTitle(title: String?) {
        this.title.text = title
    }

    fun setInputHint(hint: String?) {
        input.hint = hint
    }

    fun setInputText(text: String?) {
        input.setText(text)
    }

    fun getInputText(): String {
        return input.text.toString()
    }
}
